package study;
import static java.lang.System.out;

import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;


public class StartRMIClient {

	public static void main(String[] args) {
    	
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }
		
		out.println("start locale RMI client");
		try {
			Registry registry = LocateRegistry.getRegistry();		
			
			out.println("---Remote Objects---");
			for(String eachName:registry.list()){
				Remote o = registry.lookup(eachName);
				out.println(eachName+"->"+o);
			}
			
			out.println();
			
			out.println("call sayHello() of the 'test' Remote Object");
			Remote stub = registry.lookup("test");
			Method method = stub.getClass().getMethod("catSayHello");
			method.invoke(stub);
			
			Method method2 = stub.getClass().getMethod("dogSayHello");
			method2.invoke(stub);	
			
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}		
	}
	

	

}
